package com.aaa.config;

import com.aaa.pojo.*;
import com.github.pagehelper.PageInfo;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class GetEarningTool {
    public  static  void getInterest(List<MyLoan> myLoans) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for(MyLoan myLoan :myLoans ){
            String format1 = format.format(myLoan.getL_time());
            Date parse = format.parse(format1);
//            根据借贷时间，计算出年数
            Double between_year = DaysBetweenTool.dayComparePrecise(new Date(),parse);
//            计算利息=年数*年化率*本金
            double interest = myLoan.getL_fund() * myLoan.getL_lendingrate() * between_year;
//            对结果进行字符串截取
            String result = String.format("%.2f", interest);
            myLoan.setL_interest(Double.parseDouble(result));
        }
    }
    public static  void getearning(List<MyChange_Money> myChange_monies, List<MyPay_Money> myPay_monies, List<MyTerm_Financial> myTerm_financials, List<MyFund_Management> myFund_managements) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        遍历获取 myChange_monies 对earning和rate赋值
        if(myChange_monies!=null){
            for (MyChange_Money mychange :myChange_monies) {
                String format1 = format.format(mychange.getC_time());
                Date parse = format.parse(format1);
                Double between_year = DaysBetweenTool.dayComparePrecise(new Date(),parse);
                double earing = between_year * mychange.getChangeMoney().getC_yield() * mychange.getAmount()/100;
                String result = String .format("%.2f",earing);
                mychange.setC_earning(Double.parseDouble(result));
                double Rate = Double.parseDouble(result) / mychange.getAmount() * 100;
                double avgRate = Double.parseDouble(String.format("%.2f", Rate));
                mychange.setC_avgRate(avgRate);
            }
        }
        //        遍历获取 myPay_monies 对earning和rate赋值
       if(myPay_monies!=null){
           for (MyPay_Money mypay :myPay_monies) {
               String format1 = format.format(mypay.getP_time());
               Date parse = format.parse(format1);
               Double between_year = DaysBetweenTool.dayComparePrecise(new Date(),parse);
               double earing = between_year * mypay.getPayMoney().getPay_rate() * mypay.getAmount()/100;
               String result = String .format("%.2f",earing);
               mypay.setP_earning(Double.parseDouble(result));
               double Rate = Double.parseDouble(result) / mypay.getAmount() * 100;
               double avgRate = Double.parseDouble(String.format("%.2f", Rate));
               mypay.setP_avgRate(avgRate);
           }
       }
        //        遍历获取 myTerm_financials 对earning和rate赋值
       if(myTerm_financials!=null){
           for (MyTerm_Financial myterm :myTerm_financials) {
               String format1 = format.format(myterm.getT_time());
               Date parse = format.parse(format1);
               Double between_year = DaysBetweenTool.dayComparePrecise(new Date(),parse);
               double earing = between_year * myterm.getTermFinancial().getT_yield() * myterm.getAmount()/100;
               String result = String .format("%.2f",earing);
               myterm.setT_earning(Double.parseDouble(result));
               double Rate = Double.parseDouble(result) / myterm.getAmount() * 100;
               double avgRate = Double.parseDouble(String.format("%.2f", Rate));
               myterm.setT_avgRate(avgRate);
           }
       }
        //        遍历获取 myFund_managements 对earning和rate赋值
        if(myFund_managements!=null){
            for (MyFund_Management myfund :myFund_managements) {
                String format1 = format.format(myfund.getF_time());
                Date parse = format.parse(format1);
                Double between_year = DaysBetweenTool.dayComparePrecise(new Date(),parse);
                double earing = between_year * myfund.getFundManagement().getGrowthRate().getG_year() * myfund.getAmount()/100;
                String result = String .format("%.2f",earing);
                myfund.setF_earning(Double.parseDouble(result));
                double Rate = Double.parseDouble(result) / myfund.getAmount() * 100;
                double avgRate = Double.parseDouble(String.format("%.2f", Rate));
                myfund.setF_avgRate(avgRate);
            }
        }

    }
}
